<template>
  <div class="Clent" >
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      :collapse="isCollapse"
      @open="handleOpen"
      @close="handleClose"
      :unique-opened="true"
      :router="true"
      :class="stort.Dark?'ader':'bder'"
    >
      <!-- <div class="logo">
          <div class="limg"><img src="../assets/logo.png" alt=""></div>
          <div class="wen">BIG CUTE</div>
        </div>    -->
      <el-menu-item index="logo">
        <el-icon
          ><img
            src="../assets/logo.png"
            alt=""
            style="width: 25px; height: 20px"
        /></el-icon>
        <template #title>BIG CUTE</template>
      </el-menu-item>

      <!-- <el-menu-item index="home/index">
      <el-icon><UserFilled/></el-icon>
      <template #title>首页</template>
    </el-menu-item> -->
      <!-- <el-sub-menu index="/home/management">
      <template #title>
        <el-icon><UserFilled /></el-icon>
        <span>大屏管理</span>
      </template>

      <el-menu-item index="1-3">
        <el-icon><icon-menu /></el-icon>
        <template #title>就业态势</template>
      </el-menu-item>
      <el-menu-item index="1-3">
        <el-icon><icon-menu /></el-icon>
        <template #title>智能检测</template>
      </el-menu-item>
      <el-menu-item index="1-3">
        <el-icon><icon-menu /></el-icon>
        <template #title>安防管理</template>
      </el-menu-item>
      <el-menu-item index="1-3">
        <el-icon><icon-menu /></el-icon>
        <template #title>设备运维</template>
      </el-menu-item>
    </el-sub-menu>
    <el-sub-menu index="">
      <template #title>
        <el-icon><UserFilled /></el-icon>
        <span>知识点</span>
      </template>
      <el-menu-item-group title="Group Two">
        <el-menu-item index="1-3">item three</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="1-4">
        <template #title><span>item four</span></template>
        <el-menu-item index="1-4-1">item one</el-menu-item>
      </el-sub-menu>
    </el-sub-menu> -->

      <!-- <el-sub-menu v-for="(item, index) in res" :key="index" :index="index">
        <template #title>
          <el-icon><component :is="item.meta.icon"></component></el-icon>
          <span >{{ item.meta.title }}</span>
        </template>
        <el-menu-item
          v-for="(i, index) in item.children"
          :key="index"
          @click="lu(i)"
        >
          <el-icon><component :is="i.meta.icon"></component></el-icon>
          <template #title>{{ i.meta.title }}</template>
        </el-menu-item>

        <el-sub-menu>
          <template #title><span>item four</span></template>
          <el-menu-item index="1-4-1">item one</el-menu-item>
        </el-sub-menu>
      </el-sub-menu> -->
      <Menu :routes="homeRouter" ></Menu>
    </el-menu>

    <div class="right">
      <div class="right-top" :style="{background: stort.barColor}">
        <div class="right-top-left" style="margin-top: 10px">
          <el-radio-group>
            <!-- <el-radio-button :value="false">expand</el-radio-button>
            <el-radio-button :value="true">collapse</el-radio-button> -->
            <!-- 面包屑 -->
            <div class="icon-top">
              <el-icon @click="serol()">
                <Fold />
              </el-icon>
            </div>
            <Breadcrumb></Breadcrumb>
          </el-radio-group>
        </div>
        <div class="right-top-right">
          <!-- 搜索 -->
          <el-icon class="icon-style"><Search /></el-icon>
          <!-- 刷新 -->
          <el-icon class="icon-style" @click="refresh"><Refresh /></el-icon>

          <!-- 铃铛 -->
          <el-icon class="icon-style"><bell /></el-icon>
          <!-- 全屏 -->
          <el-icon id="fullscreen" class="icon-style" @click="handleFullScreen">
            <component :is="icon ? 'Rank' : 'FullScreen'"></component>
          </el-icon>
          <!-- 头像 -->
          <el-dropdown placement="bottom">
            <div class="flx-center">
              <div class="avatar">
                <img :src="img" alt="avatar" />
              </div>
              <span class="username">BIG CUTE</span>
            </div>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人中心</el-dropdown-item>
                <el-dropdown-item @click="gotoLogin">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <!-- 设置 -->
          <!-- <el-icon @click="openDrawer" class="icon-style"><Setting /></el-icon> -->
          <SheZhi></SheZhi>
        </div>
      </div>

      <!-- 路由出口 -->
      <div class="right-cent">
        <div class="right-cent-top" :class="stort.HiddenDisplay?'ying':'xian'">
          <el-button
            type="primary"
            v-for="(item, index) in historv"
            :key="index"
            @click="routees(item)"
          >
            {{ item.meta.title }} &ensp;
            <el-icon @click="delet(item)">
              <CircleClose />
            </el-icon>
          </el-button>
        </div>

        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, inject, reactive, watch } from "vue";
import { useRoute } from "vue-router";
import screenfull from "screenfull";
import Breadcrumb from "@/components/Breadcrumb.vue";
import {
  Document,
  UserFilled,
  Menu as IconMenu,
  Setting,
  Avatar,
  HomeFilled,
} from "@element-plus/icons-vue";
import { getmenulist } from "@/api/server";
import router from "@/router";
import Menu from "../components/menu/IcoMenu.vue";
import { homeRouter } from "@/router/index";
// import Menu from '../components/Menu.vue'
import { useCounterStore } from "@/stores/Shi";

import SheZhi from "@/components/hearde/SheZhi.vue";
const openDrawer = () => {};

const stort = useCounterStore();

// const themeConfig = stort.themeConfig;

const isCollapse = ref(true);

// 折叠
const serol = () => {
  isCollapse.value = !isCollapse.value;
};

// 路由渲染
const route = useRoute();
console.log(route, "mlp");
const res = route.matched[0].children;
console.log(res, "1234567");

const disabled = ref(false);
const img = localStorage.getItem("img");
console.log(img, "img");

// 刷新
const refresh = inject("reload1");

console.log(refresh, "23454678");

// 全屏
let icon = ref(screenfull.isFullscreen);
const handleFullScreen = () => {
  if (screenfull.isEnabled) {
    screenfull.toggle();
  }
};

// 退出登录
const gotoLogin = () => {
  sessionStorage.removeItem("token");
  router.push("/login");
};

const handleOpen = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath);
};
const handleClose = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath);
};

// const add = (item: any) => {
//   router.push(item.path);
// };
const lu = (i: any) => {
  router.push(i.path);
};

const routee = useRoute();
const historv = reactive<any[]>([]);

watch(
  //监听实现面包屑添加效果
  routee,
  () => {
    if (historv.every((item: any) => item.path !== routee.path)) {
      historv.push({
        name: routee.name,
        path: routee.path,
        query: routee.query,
        meta: routee.meta,
      });
    }
    console.log(historv, "=========historv");
  }
);
// 点击添加
const routees = (item: any) => {
  router.push(item.path);
};

// 点击删除
const delet = (item: any) => {
  const deindex = historv.findIndex((i) => i.name === item.name);
  historv.splice(deindex, 1);
};
</script>

<style scoped lang="scss">
.icon-style {
  font-size: 20px;
  cursor: pointer;
  margin: 0 0 0 11px;
}
/* .el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
} */
// .affix-container {
//   text-align: center;
//   // height: 100%;
//   border-radius: 4px;
//   background: var(--el-color-primary-light-9);
// }
.el-dropdown {
  cursor: pointer;
  .el-tooltip__trigger {
    display: flex;
    flex-flow: row;
    align-items: center;
  }
}
.username {
  font-size: 15px;
  margin: 0 0 0 10px;
}

.avatar {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  margin-left: 20px;
  img {
    width: 100%;
    height: 100%;
  }
}

.Clent {
  display: flex;
  // justify-items: center;
  height: 100%;
}

.right {
  flex: 1;
  background: #ccc;
  height: 1000px;
}
.right-top {
  width: 100%;
  height: 40px;
  background: #fff;
  .el-icon {
    margin-top: 2%;
    font-size: 20px;
    margin-left: 10px;
    margin-right: 10px;
  }
}
.right-top-left {
  float: left;
}
.right-top-right {
  float: right;
}
.right-cent {
  width: 100%;
  height: 100%;
}

.right-cent-top {
  margin-top: 10px;
  // width: 100%;
  line-height: 250%;
  height: 4%;
  margin-bottom: 10px;
  background: #fff;
}
.ader{
  background: #000000;
  color: #ffffff;
}
.bder{
  background: #ffffff;
  color: #000000;
}
.ying{
  display: none;
}

.xian{
  display: block;
}
</style>